//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_createplayerbike.sqf"
#include "x_setup.sqf"

private ["_unit","_vtype","_pos","_vehicle","_b_mode","_water"];
PARAMS_3(_unit,_vtype,_b_mode);
__TRACE_1("_this","_this")
_pos = position _unit;
// TYRGHEN - Added boat check
if (_vtype isKindOf "Ship") then {
	{ _water = [getPos _unit, _x] call FUNC(findWater);
	if (count _water == 3) then {
		__TRACE_1("_water","_water");
		_pos = _water;
	};
	} foreach [40,30,20,10];
};
__TRACE_1("_pos","_pos")
_vehicle = createVehicle [_vtype, _pos, [], 0, "NONE"];
_vehicle setDir direction _unit;
//_vehicle setPos _pos;
// TYRGHEN - Added boat check
if !(_vtype isKindOf "Ship") then {
	[QGVAR(stocbike), [_unit, _vehicle]] call FUNC(NetCallEventSTO);
};
if (_b_mode == 1) then {
	__addDead(_vehicle);
} else {
	_vehicle setVariable [QGVAR(end_time), _this select 3];
	GVAR(allunits_add) set [count GVAR(allunits_add), _vehicle]
};